package sj;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.*;

public class UserMapperTest {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;

        User user=new User();
        Class clazz= UserMapper.class;

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            Method method=clazz.getMethod("findAll");
            Mybatis mybatis=method.getAnnotation(Mybatis.class);

            String sql=mybatis.sql();
            String resultType=mybatis.resultType();

            conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/ktmall?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8","root","123456");
            ps=conn.prepareStatement(sql);

            rs=ps.executeQuery();

            while (rs.next()){
                Class clazzs=Class.forName(resultType);
                Field[] fields=clazzs.getDeclaredFields();
                for (Field f:fields){
                    Object obj=rs.getObject(f.getName());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (conn != null) {
                try {
                    if (rs!=null){
                        rs.close();
                    }

                    if (ps!=null){
                        ps.close();
                    }

                    conn.close();
                }catch (SQLException e){
                    e.printStackTrace();
                }
            }
        }

    }
}
